ac = [
    [0,-2,-7,0],
    [9,2,-6,2],
    [-4,1,-1,1],
    [-1,8,0,-2]
]

def AcSum(start, end):
    s = 0
    for x in range(start[0], end[0] + 1):
        for y in range(start[1],end[1] + 1):
            s += ac[x][y]
    return s

def AllAc():
    acc = []
    for sy in range(0, len(ac)):
        for sx in range(0, len(ac[0])):
            for ey in range(sy + 1, len(ac)):
                for ex in range(sx + 1, len(ac[0])):
                    sP = (sx, sy)
                    eP = (ex, ey)
                    s = AcSum(sP,eP)
                    acc.append((sP,eP,s))
    return acc

def GetAnswer(acc):
    allSum = []
    for i in acc:
        allSum.append(i[2])
    answer = max(allSum)
    return answer
    
def main():
    ac = AllAc()
    print(GetAnswer(ac))
    
if __name__ == '__main__':
    main()
